package utils;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;

public class JsonUtil {

    public static void writerObjToString(HttpServletResponse response, Object obj) {
        try {
            ObjectMapper om = new ObjectMapper();
            String jsonStr = om.writeValueAsString(obj);
            // 统一设置编码
            response.setContentType("application/json;charset=utf8");
            response.getWriter().write(jsonStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
